package com.gopay.common.cps.dao.bank.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.bank.BisBankGFBConfigQueryDAO;
import com.gopay.common.domain.acps.DeleteFlag;
import com.gopay.common.domain.bis.BisBankGFBConfig;

/**
 * 国付宝银行账户信息配置表DAO实现
 * 
 * @BisBankGFBConfigQueryDAOImpl.java
 * @author MA HUAN
 * @2013-8-9 下午4:05:51 www.gopay.com.cn Inc.All rights reserved.
 */

@Repository(value = "bisBankGFBConfigQueryDAO")
public class BisBankGFBConfigQueryDAOImpl extends
		BaseDAOImpl<BisBankGFBConfig, String> implements BisBankGFBConfigQueryDAO {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
    public List<BisBankGFBConfig> getOfflineChargeBankList() {
         String hql = "from BisBankGFBConfig bi where bi.offlineChargeSupport = 1 and bi.del = :DEL_FLAG";
         Map params = new HashMap();
		 params.put("DEL_FLAG", DeleteFlag.N.ordinal());
        return super.findByHql(hql, params);
    }

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public BisBankGFBConfig getOfflineChargeBankByCode(String bankCode) {
		 String hql = "from BisBankGFBConfig bi where bi.offlineChargeSupport = 1 and bi.bankCode = :BankCode and bi.del = :DEL_FLAG";
		 
		 Map params = new HashMap();
		 params.put("DEL_FLAG", DeleteFlag.N.ordinal());
		 params.put("BankCode", bankCode);
	     List<BisBankGFBConfig>  res = super.findByHql(hql, params);
	     if(res != null) {
	    	 if(res.size() > 1) {
	    		 throw new RuntimeException("Illegal Data State, More than 1 Record Selected from Database!");
	    	 }
	    	 return res.get(0);
	     }
	     return null;
	}

	@Override
	public BisBankGFBConfig getOfflineChargeBankByAcctNum(String acctNum) {
		 String hql = "from BisBankGFBConfig bi where bi.offlineChargeSupport = 1 and bi.acctNum = :AcctNum and bi.del = :DEL_FLAG";
		 
		 Map params = new HashMap();
		 params.put("DEL_FLAG", DeleteFlag.N.ordinal());
		 params.put("AcctNum", acctNum);
	     List<BisBankGFBConfig>  res = super.findByHql(hql, params);
	     if(res != null) {
	    	 if(res.size() > 1) {
	    		 throw new RuntimeException("Illegal Data State, More than 1 Record Selected from Database!");
	    	 }
	    	 return res.get(0);
	     }
	     return null;
	}
}
